package com.founder.bdyx.modules.sys.controller;

import com.founder.bdyx.core.entity.ProcessResult;
import com.founder.bdyx.core.result.PageResult;
import com.founder.bdyx.core.util.DictConvertUtil;
import com.founder.bdyx.modules.sys.model.ApplyInfo;
import com.founder.bdyx.modules.sys.service.ApplyInfoService;
import com.founder.bdyx.wxpro.conf.WxConfig;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

import static com.founder.bdyx.core.entity.ProcessResult.ERROR;

@RestController
@RequestMapping("/sys/close")
public class CloseOrderController {
    Log log = LogFactory.getLog(CloseOrderController.class);

    @Autowired
    private ApplyInfoService applyInfoService;
    @Autowired
    private WxConfig wxConfig;

    @ApiOperation(value = "闭环列表视图",notes = "闭环列表视图")
    @GetMapping("/list")
    public ModelAndView list() {
        return new ModelAndView("/modules/close/list");
    }

    @ApiOperation(value = "获取闭环列表",notes = "获取闭环列表")
    @RequestMapping(value = "",method = RequestMethod.GET)
    public Page<ApplyInfo> getAll(@ApiParam(name = "keyword",value="查询字段",required = false) String keyword,String paystatus) {
        Page<ApplyInfo> applyInfos = applyInfoService.getClosedAll(keyword,paystatus);
        if(applyInfos != null && applyInfos.size()>0)
            DictConvertUtil.converter(applyInfos);
        return applyInfos;
    }

    @ApiOperation(value = "申请详情视图",notes = "申请详情视图")
    @RequestMapping(value = "/form",method = RequestMethod.GET)
    public ModelAndView form() {
        return new ModelAndView("/modules/close/form");
    }

    @ApiOperation(value = "获取申请详细信息",notes = "获取申请详细信息")
    @PostMapping(value = "/view/{id}")
    public ApplyInfo view(@ApiParam(name = "id", value = "申请单id", required = true) @PathVariable String id){
        ApplyInfo applyInfo = applyInfoService.getByAppId(id);
        DictConvertUtil.converter(applyInfo);
        return applyInfo;
    }
}
